import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:path/path.dart';

class IconHelper{
  static Map<String,IconData> FileIconList=<String,IconData>{};
  static Map<String,Color> FileColorList=<String,Color>{};

  static void GetIconList(){
    FileIconList= Map();
    FileIconList[".jpg"]=FontAwesomeIcons.fileImage;
    FileIconList[".png"]=FontAwesomeIcons.fileImage;
    FileIconList[".txt"]=FontAwesomeIcons.fileAlt;
    FileIconList[".xls"]=FontAwesomeIcons.fileExcel;
    FileIconList[".xlsx"]=FontAwesomeIcons.fileExcel;
    FileIconList[".doc"]=FontAwesomeIcons.fileWord;
    FileIconList[".docx"]=FontAwesomeIcons.fileWord;
    FileIconList[".ppt"]=FontAwesomeIcons.filePowerpoint;
    FileIconList[".pptx"]=FontAwesomeIcons.filePowerpoint;
    FileIconList[".pdf"]=FontAwesomeIcons.filePdf;
    FileIconList[".mp4"]=FontAwesomeIcons.fileVideo;
    
    //FileIconList[".zip"]=FontAwesomeIcons.fileMedical;
    //FileIconList[".rar"]=FontAwesomeIcons.fileMedical;
  }

   static void GetColorList(){
    FileColorList=  Map();
    FileColorList[".jpg"]=Colors.orange;
    FileColorList[".png"]=Colors.orange;
    FileColorList[".txt"]=Colors.grey;
    FileColorList[".xls"]=Colors.green;
    FileColorList[".xlsx"]=Colors.green;
    FileColorList[".doc"]=Colors.blue;
    FileColorList[".docx"]=Colors.blue;
    FileColorList[".ppt"]=Colors.pink;
    FileColorList[".pptx"]=Colors.pink;
    FileColorList[".pdf"]=Colors.red;
    FileColorList[".mp4"]=Colors.grey;
  }

  ///GetFileIcon 获取File图标
  static Icon getFileIcon(String path,double size){
     var hz= extension(path);
     return Icon(getIconData(hz),color: getIconColor(hz),size: size,);
  }

  static IconData getIconData(String key){
    if(FileIconList.isEmpty){
       GetIconList();
     }
     if(FileIconList.containsKey(key)) {
       return  FileIconList[key]!;
     }

     return FontAwesomeIcons.file;

  }


   static Color getIconColor(String key){
    if(FileColorList.isEmpty){
       GetColorList();
     }
     if(FileColorList.containsKey(key)) {
       return  FileColorList[key]!;
     }

     return Colors.grey;

  }

}